package org.liveboardgames.agricola.model.structure;

import java.util.HashSet;

import org.liveboardgames.agricola.domain.action.Action;
import org.liveboardgames.agricola.domain.board.BoardTile;
import org.liveboardgames.agricola.domain.card.BakingImprovementCard;
import org.liveboardgames.agricola.domain.card.Card;
import org.liveboardgames.agricola.domain.card.CookingImprovementCard;
import org.liveboardgames.agricola.domain.card.ImprovementCard;
import org.liveboardgames.agricola.domain.card.ReferenceBakingImprovementCard;
import org.liveboardgames.agricola.domain.card.ReferenceCard;
import org.liveboardgames.agricola.domain.card.ReferenceCookingImprovementCard;
import org.liveboardgames.agricola.domain.card.ReferenceImprovementCard;
import org.liveboardgames.agricola.domain.common.AlternativeCost;
import org.liveboardgames.agricola.domain.farm.Farm;
import org.liveboardgames.agricola.domain.farm.FarmTile;
import org.liveboardgames.agricola.domain.player.Player;

public class GameLoadVisitor implements Visitor {

  public void visit(Visitable visitable) {
    // TODO Auto-generated method stub

  }

  public void visit(Action action) {
    // TODO Auto-generated method stub

  }

  public void visit(Card card) {
    ReferenceCard refCard = card.getRefCard();

    if (refCard != null) {

      card.setCardName(refCard.getCardName());
      card.setChangingType(refCard.getChangingType());
      card.setFamilyType(refCard.getFamilyType());
      card.setImagePath(refCard.getImagePath());
      card.setNumberOfPlayers(refCard.getNumberOfPlayers());
      // card.setPeeps(refCard.getPeeps());
      card.setPeriod(refCard.getPeriod());
      card.setPoints(refCard.getPoints());
      card.setResourceZone(refCard.getResourceZone());
      card.setSpecialPoints(refCard.getSpecialPoints());

      TargetReplacementVisitor visitor = new TargetReplacementVisitor(refCard, card);

      if (refCard.getActions() != null) {
        card.setActions(new HashSet<Action>());
        for (Action action : refCard.getActions()) {
          Action newAction = action.clone();
          newAction.acceptVisit(visitor);
          card.getActions().add(newAction);
        }
      }

      if (refCard.getExclusiveActions() != null) {
        card.setExclusiveActions(new HashSet<Action>());
        for (Action action : refCard.getExclusiveActions()) {
          Action newAction = action.clone();
          newAction.acceptVisit(visitor);
          card.getExclusiveActions().add(newAction);
        }
      }

      card.setRefCard(null);
    }
  }

  public void visit(BakingImprovementCard card) {
    ReferenceCard refCard = card.getRefCard();
    if (refCard != null && refCard instanceof ReferenceBakingImprovementCard) {
      ReferenceBakingImprovementCard ref = (ReferenceBakingImprovementCard)refCard;
      card.setFoodPerUse(ref.getFoodPerUse());
      card.setNbOfUses(ref.getNbOfUses());
    }
  }

  public void visit(CookingImprovementCard card) {
    ReferenceCard refCard = card.getRefCard();
    if (refCard != null && refCard instanceof ReferenceCookingImprovementCard) {
      ReferenceCookingImprovementCard ref = (ReferenceCookingImprovementCard)refCard;
      card.setBoar(ref.getBoar());
      card.setCattle(ref.getCattle());
      card.setSheep(ref.getSheep());
      card.setVegetable(ref.getVegetable());
    }
  }

  public void visit(ImprovementCard card) {
    ReferenceCard refCard = card.getRefCard();
    if (refCard != null && refCard instanceof ReferenceImprovementCard) {
      ReferenceImprovementCard ref = (ReferenceImprovementCard)refCard;
      card.setCategory(ref.getCategory());
      card.setCost(ref.getCost());
      card.setAlternativeCosts(ref.getAlternativeCosts());
      card.setTypes(ref.getTypes());
    }
  }

  public void visit(Player player) {
    // TODO Auto-generated method stub

  }

  public void visit(Farm farm) {
    // TODO Auto-generated method stub

  }

  public void visit(FarmTile farmTile) {
    // TODO Auto-generated method stub

  }

  public void visit(BoardTile boardTile) {
    // TODO Auto-generated method stub

  }

  public void visit(AlternativeCost cost) {
    // TODO Auto-generated method stub

  }

}
